﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using Controller;
using BusinessModel.Reports;

namespace ManageStore.Forms
{
    public partial class FrmReportViewer : Form
    {
        public FrmReportViewer()
        {
            InitializeComponent();
        }

        private void FrmReportViewer_Load(object sender, EventArgs e)
        {
            this.reportViewer1.RefreshReport();
        }

        #region Properties
        public int ProductCount { get; set; }
        public int ProductIndex { get; set; }
        public object LstDataSource
        { 
            get
            {
                return this.bindingSource1.DataSource;
            } 
            set
            {
                this.bindingSource1.DataSource = value;
                ReportDataSource.Value = this.bindingSource1;
            }
        }
        private ReportDataSource ReportDataSource { get; set; }
        #endregion Properties

        public event EventHandler<PageNavigationEventArgs> EvtPageNavigation;

        public void Mtd_LoadReport(string pReportSource, string pDataSetName, string pTitle, object pDataSource, bool pIsConsign)
        {
            this.reportViewer1.LocalReport.ReportEmbeddedResource = pReportSource;
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter("Title", pTitle));
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter("IsConsign", pIsConsign.ToString()));
            this.bindingSource1.DataSource = pDataSource;
            ReportDataSource = new ReportDataSource(pDataSetName, this.bindingSource1);
            this.reportViewer1.LocalReport.DataSources.Clear();
            this.reportViewer1.LocalReport.DataSources.Add(ReportDataSource);
            //SetDataSource(pDataSource);
        }

        public void RefreshReport()
        {
            this.reportViewer1.RefreshReport();
        }
        private void reportViewer1_PageNavigation(object sender, PageNavigationEventArgs e)
        {
            if (EvtPageNavigation != null)
                EvtPageNavigation(sender, e);
        }
    }
}
